#include "TimeStamp.h"
#include <ctime>
namespace mymuduo
{

TimeStamp::TimeStamp() {}
TimeStamp::TimeStamp(int64_t micro_seconds_since_epoch) : micro_seconds_since_epoch_(micro_seconds_since_epoch){}
TimeStamp TimeStamp::now() {
    // 返回自1970年1月1日00:00:00 UTC（称为Epoch时间）到当前时间的秒数
    return TimeStamp(time(nullptr)); // 如果参数 timer 不为空，返回的时间值也会存储在 timer 指向的变量中
}
std::string TimeStamp::toString() const {
    char buf[128] = {0};
    // 转化为当前时间 
    tm* tm_time = localtime(&micro_seconds_since_epoch_);
    snprintf(buf, 128, "%4d/%02d/%02d %02d:%02d:%02d", 
        tm_time->tm_year + 1900, tm_time->tm_mon + 1, tm_time->tm_mday,
        tm_time->tm_hour, tm_time->tm_min, tm_time->tm_sec);
    return std::string(buf);
}
} // namespace name
